//
//  SelectPayViewController.m
//  EasyToo
//
//  Created by linshengqin on 13-9-2.
//
//

#import "SelectPayViewController.h"
#import "CarShipConfirmViewController.h"
@interface SelectPayViewController ()

@end

@implementation SelectPayViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
     [self.view setBackgroundColor:BackgroundColor];
    [self initMainView];
    [self createPhoneTextfield];
    [self createtipsLabel];
    [self createLabelOne];
    [self createLabelTwo];
    [self createFlagFirst];
    [self createFlagSecond] ;
    [self createWayOfPayButtonOne];
    [self createWayOfPayButtonTwo];
    [self createNextStepButton];
}

-(void)initMainView
{
    _bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight])];
    [self.view addSubview:_bgScrollView];
    _bgScrollView.contentSize = CGSizeMake(320, 700);
    _bgScrollView.showsVerticalScrollIndicator = YES;
    
}


-(void)createPhoneTextfield
{
    UITextField *PhoneNumberTextfiled = [[UITextField alloc]initWithFrame:CGRectMake(10, 70, 300, 50)];
    PhoneNumberTextfiled.placeholder= @"手机号码" ;
    PhoneNumberTextfiled.font = [UIFont fontWithName:@"Arial" size:18.0f];
    PhoneNumberTextfiled.textColor = [UIColor blackColor];
    PhoneNumberTextfiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    PhoneNumberTextfiled.borderStyle = UITextBorderStyleRoundedRect;
    PhoneNumberTextfiled.delegate = self ;
    PhoneNumberTextfiled.returnKeyType =UIReturnKeyDone;
//    PhoneNumberTextfiled.layer.borderColor = [UIColor grayColor].CGColor;
//    PhoneNumberTextfiled.layer.borderWidth = 1 ;
//    PhoneNumberTextfiled.layer.cornerRadius = 10 ;
    
    [_bgScrollView addSubview:PhoneNumberTextfiled];
    [PhoneNumberTextfiled release];
    
}
-(void)createtipsLabel
{
    UILabel *warmTipslabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 120, 300, 60)];
    warmTipslabel.numberOfLines = 0;
    warmTipslabel.text = @"温馨提示:为确保您委托的业务顺利办理进行，请务必留下您的联系方式，业务办理完成后，我们的客服人员将会根据你所留的电话通知您。" ;
    warmTipslabel.font = [UIFont systemFontOfSize:10];
    warmTipslabel.textColor = [UIColor grayColor];
    [warmTipslabel setBackgroundColor:[UIColor clearColor]];

    [_bgScrollView addSubview:warmTipslabel];
    [warmTipslabel release];
    
}
-(void)createLabelOne
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(30, 30, 150, 30)];
    label.text = @"填写联系方式";
    label.textAlignment = NSTextAlignmentLeft ;
    label.font = [UIFont fontWithName:@"Arial" size:18.0f];
    label.textColor = [UIColor blackColor];
    [label setBackgroundColor:[UIColor clearColor]];

    [_bgScrollView addSubview:label];
    [label release];
}
-(void)createFlagFirst
{
    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 40, 10, 10)];
    imageview.image = [UIImage imageNamed:@"shurubi"];
    [_bgScrollView addSubview:imageview];
    [imageview release];
}
-(void)createLabelTwo
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(30, 200, 150, 30)];
    label.text = @"选择支付方式";
    label.textAlignment = NSTextAlignmentLeft ;
    label.font = [UIFont fontWithName:@"Arial" size:18.0f];
    label.textColor = [UIColor blackColor];
    [label setBackgroundColor:[UIColor clearColor]];

    [_bgScrollView addSubview:label];
    [label release];
    
}
-(void)createFlagSecond
{
    UIImageView * imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 210, 10, 10)];
    imageview.image = [UIImage imageNamed:@"select_button.png"];
    [_bgScrollView addSubview:imageview];
    [imageview release];
}

#pragma mark (tag 3 ~ 6)
-(void)createWayOfPayButtonOne
{
     _ylButton =[[UIButton alloc]initWithFrame:CGRectMake(105, 240, 100, 40)];
    [_ylButton setBackgroundImage:[UIImage imageNamed:@"yinlian1.png"] forState:UIControlStateNormal];
    [_ylButton setBackgroundImage:[UIImage imageNamed:@"yinlian2.png"] forState:UIControlStateSelected];

    [_ylButton addTarget:self action:@selector(selectPayOne:) forControlEvents:UIControlEventTouchUpInside];
    _ylButton.tag = 3 ;
//    btn.layer.cornerRadius =10 ;
    [_bgScrollView addSubview:_ylButton];
    [_ylButton release];
}
-(void)selectPayOne:(UIButton *)btn
{
    [_ylButton setSelected:YES];
    [_zfbButton setSelected:NO];
}
-(void)createWayOfPayButtonTwo
{
    /*
    _zfbButton=[[UIButton alloc]initWithFrame:CGRectMake(170, 240, 105, 40)];
    [_zfbButton setBackgroundImage:[UIImage imageNamed:@"zfb.png"] forState:UIControlStateNormal];
    [_zfbButton setBackgroundImage:[UIImage imageNamed:@"zhifubao2.png"] forState:UIControlStateSelected];

    [_zfbButton addTarget:self action:@selector(selectPayTwo:) forControlEvents:UIControlEventTouchUpInside];
    _zfbButton.tag = 5 ;
//    btn.layer.cornerRadius =10 ;
    [_bgScrollView addSubview:_zfbButton];
    [_zfbButton release];
    */
}
-(void)selectPayTwo:(UIButton *)btn
{
    [_zfbButton setSelected:YES];
    [_ylButton setSelected:NO];
}
-(void)createNextStepButton
{
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, 330, 300, 50)];
    [btn setBackgroundImage:[UIImage imageNamed:@"button_3.png"] forState:UIControlStateNormal];
    [btn setTitle:@"下一步" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(nextStep) forControlEvents:UIControlEventTouchUpInside];
//    btn.layer.cornerRadius =10 ;
    
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_bgScrollView addSubview:btn];
    [btn release];
}
-(void)nextStep
{
    
    
    if(_ylButton.selected)
    {
        [datamodel.payWatStr setString:@"网银支付"] ;
    }
    else
        [datamodel.payWatStr setString:@"支付宝"] ;
        
    NSLog(@"payWatStr :%@",datamodel.payWatStr) ;
    
    if([datamodel.phoneNumStr length] <= 0)
    {
        UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"设置未完整" delegate:self.view cancelButtonTitle:@"ok" otherButtonTitles : nil];
        [alertview show] ;
        [alertview release] ;
        
    }
    else
    {
        CarShipConfirmViewController  *confirm = [[CarShipConfirmViewController alloc]init];
        [self.navigationController pushViewController:confirm animated:YES];

//        [self presentViewController:comfirmCtl animated:YES completion:nil];
        
    }
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    datamodel = [ConfirmDataModel shareData];
    [datamodel.phoneNumStr setString: [NSString stringWithFormat:@"%@",textField.text]] ;
    NSLog(@"phoneNumStr :%@",datamodel.phoneNumStr) ;
    [textField resignFirstResponder];
    
    return  YES ;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
